#if !USE_CONSOLE

#include "src/interface/window.h"

#include <vector>
#include <iostream>


#include "src/interface/lightDialog.h"
#include "src/interface/objectDialog.h"
#include "src/interface/operationDialog.h"
#include "src/interface/rayTestPanel.h"
#include "src/interface/input.h"
#include "src/interface/treeWidget.h"

#include "src/defines/primitive.h"
#include "src/defines/operation.h"

#include "src/scene/combinedObject.h"
#include "src/scene/cuboidPrimitive.h"
#include "src/scene/spherePrimitive.h"
#include "src/scene/cylinderPrimitive.h"
#include "src/scene/conePrimitive.h"

Window::Window(){
	setWindowTitle(QString::fromUtf8("[CGII] Raytracing++"));
    statusBar()->showMessage(tr(""));
    setUnifiedTitleAndToolBarOnMac(true);

	canvas = new GLWidget(this);
	setCentralWidget(canvas);

	createWindow();

//	setSize(QSize(800, 100));
}

Window::~Window(){
	if(canvas) delete canvas;
    if(geometricOperationToolBar) delete geometricOperationToolBar;
    if(setOperationToolBar) delete setOperationToolBar;
    if(editObjectAct) delete editObjectAct;
    if(deleteObjectAct) delete deleteObjectAct;
    if(duplicateObjectAct) delete duplicateObjectAct;
    if(cameraPanel) delete cameraPanel;
    if(scenePanel) delete scenePanel;
    if(renderPanel) delete renderPanel;
}

QSize Window::sizeHint() const {
	return QSize(1900, 600);
}

void Window::testRaytracing(Ray _r){
    canvas->getScene()->testRaytracing(_r);
//    canvas->changeShowRayTest(true);
    rayTestViewAct->setChecked(true);
    canvas->updateGL();
}

Scene *Window::newScene(bool _fromFile){
    Scene *s = canvas->newScene();

    if(!_fromFile){
        //pqrque se for por arquivo, ja estah dudando disso em outro lugar
        cameraPanel->setCamera(canvas->getScene()->getCamera());
        scenePanel->setScene(s);
        output.setFile(NULL);
        renderPanel->setRender();
    }


    updateActionsFromChanging();
    return s;
}

void Window::openObjects(){
    QString filename = QFileDialog::getOpenFileName(this, tr("Acrescentar objetos"), QDir::currentPath(),tr("Arquivo de cenas (*.obs)"));

    if (!filename.isNull()){
//        qDebug() << "abrindo: " << filename;
        QFile* file = new QFile(filename);

        Input input;
        std::vector<Object *> objs = input.parseScene(file, canvas->getScene(), canvas, true);
        scenePanel->update(NULL, &objs);
        canvas->updateGL();

        output.setFile(file);
	}
	updateActionsFromChanging();
//	updateTreesVolume(false);
}

void Window::openScene(){

    std::cout <<"Podia perguntar se a pessoa quer salvar o ultimo ou não" <<std::endl;

	QString filename = QFileDialog::getOpenFileName(this, tr("Abrir cena"), QDir::currentPath(),tr("Arquivo de cenas (*.obs)"));

    if (!filename.isNull()){
        qDebug() << "abrindo: " << filename;
        QFile* file = new QFile(filename);

        Input input;
        Scene *s = newScene(true);
        input.parseScene(file, s, canvas, false);
        scenePanel->update(s);
        renderPanel->setRender();
        cameraPanel->setCamera(s->getCamera());
        canvas->updateGL();

        output.setFile(file);
	}
	updateActionsFromChanging();
}

void Window::saveScene(){
    if(output.isFileNull()){
        if(!saveSceneAs()) return;
    }

    output.parseObjects(canvas->getScene());

    saveSceneAct->setEnabled(false);
}

bool Window::saveSceneAs(){
	QString filename = QFileDialog::getSaveFileName(this, tr("Salvar cena como..."), QDir::currentPath(), tr("Arquivo cena (*.obs)"));

    if (filename.isNull()) return false;

    if (QFileInfo(filename).suffix().isEmpty())
        filename += ".obs";

    QFile* file = new QFile(filename);

	output.parseObjects(file, canvas->getScene());

    saveSceneAct->setEnabled(false);

    return true;
}

void Window::addLight(Light *_l){
//    std::cout <<"adicionando a luz! " << _l->getId() << std::endl;
    canvas->getScene()->addLight(_l);
    scenePanel->getLightsTree()->addLight(_l);

    updateActionsFromLight();

    //eu ja sei que vai ter um unico objeto sendo selecionado
//    canvas->updateGL();
}

void Window::newPointLightDialog(){
    LightDialog *dlg = new LightDialog(canvas->getScene()->nextLightsID(), POINT_LIGHT, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Light *)), this, SLOT(addLight(Light *)));
}

void Window::newAreaLightDialog(){
    LightDialog *dlg = new LightDialog(canvas->getScene()->nextLightsID(), AREA_LIGHT, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Light *)), this, SLOT(addLight(Light *)));
}

void Window::addPrimitive(Object *_obj){
    canvas->getScene()->addObject(_obj);
    scenePanel->getObjectsTree()->addObject(_obj);

    //eu ja sei que vai ter um unico objeto sendo selecionado
    updateActionsFromChanging(1);
}

void Window::newCuboidPrimitiveDialog(){
    ObjectDialog *dlg = new ObjectDialog(canvas->getScene()->nextObjectsID(), CUBOID, canvas, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Object *)), this, SLOT(addPrimitive(Object *)));
}

void Window::newSpherePrimitiveDialog(){
    ObjectDialog *dlg = new ObjectDialog(canvas->getScene()->nextObjectsID(), SPHERE, canvas, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Object *)), this, SLOT(addPrimitive(Object *)));
}

void Window::newCylinderPrimitiveDialog(){
    ObjectDialog *dlg = new ObjectDialog(canvas->getScene()->nextObjectsID(), CYLINDER, canvas, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Object *)), this, SLOT(addPrimitive(Object *)));
}

void Window::newConePrimitiveDialog(){
    ObjectDialog *dlg = new ObjectDialog(canvas->getScene()->nextObjectsID(), CONE, canvas, this);
    dlg->show();

    connect(dlg, SIGNAL(done(Object *)), this, SLOT(addPrimitive(Object *)));
}

void Window::createWindow(){

//    std::cout <<"Criando window" <<std::endl;

    //Criando paineis ----------------------------------------------------------

    QDockWidget *renderPanelDock = new QDockWidget(tr("Cena"), this);

    renderPanel = new RenderPanel(renderPanelDock, canvas);

	renderPanelDock->setWidget(renderPanel);
    renderPanelDock->setMaximumWidth(350);
    addDockWidget(Qt::LeftDockWidgetArea, renderPanelDock);





    QDockWidget *scenePanelDock = new QDockWidget(tr("Cena"), this);

    scenePanel = new ScenePanel(canvas, scenePanelDock, canvas->getScene());
    TreeWidget *objectsTree = scenePanel->getObjectsTree();
    TreeWidget *lightsTree = scenePanel->getLightsTree();

    connect(objectsTree , SIGNAL(updateActionsFromSelection(int)), this, SLOT(updateActionsFromSelection(int)));
//    connect(lightsTree , SIGNAL(updateActionsFromSelection(int)), this, SLOT(updateActionsFromSelection(int)));
    connect(objectsTree , SIGNAL(updateActionsFromEditing(int)), this, SLOT(updateActionsFromEditing(int)));
//    connect(lightsTree , SIGNAL(updateActionsFromEditing(int)), this, SLOT(updateActionsFromEditing(int)));
    connect(objectsTree , SIGNAL(updateActionsFromChanging()), this, SLOT(updateActionsFromChanging()));
//    connect(lightsTree , SIGNAL(updateActionsFromChanging()), this, SLOT(updateActionsFromChanging()));
    connect(objectsTree , SIGNAL(updateActionsFromChanging(int)), this, SLOT(updateActionsFromChanging(int)));
    connect(lightsTree , SIGNAL(updateActionsFromLight(int, int)), this, SLOT(updateActionsFromLight(int, int)));

	scenePanelDock->setWidget(scenePanel);
    scenePanelDock->setMaximumWidth(350);
//    scenePanelDock->setMinimumHeight(200);
    addDockWidget(Qt::RightDockWidgetArea, scenePanelDock);




    QDockWidget *rayTestDock = new QDockWidget(QString::fromUtf8("Teste de raio"), this);

    RayTestPanel *rayTestPanel = new RayTestPanel(rayTestDock);

	rayTestDock->setWidget(rayTestPanel);
    rayTestDock->setMaximumWidth(350);
    rayTestDock->setMaximumHeight(250);

    addDockWidget(Qt::RightDockWidgetArea, rayTestDock);

    connect(rayTestPanel, SIGNAL(test(Ray)), this, SLOT(testRaytracing(Ray)));





    QDockWidget *cameraPanelDock = new QDockWidget(QString::fromUtf8("Camera"), this);

    cameraPanel = new CameraPanel(cameraPanelDock, canvas->getScene()->getCamera());

	cameraPanelDock->setWidget(cameraPanel);
    cameraPanelDock->setMaximumWidth(350);

    addDockWidget(Qt::RightDockWidgetArea, cameraPanelDock);
    tabifyDockWidget(cameraPanelDock, rayTestDock);
    tabifyDockWidget(cameraPanelDock, scenePanelDock);

    connect(cameraPanel, SIGNAL(update()), canvas, SLOT(updateGL()));






    //Criando ações ------------------------------------------------------------
    QAction *newSceneAct = new QAction(QString::fromUtf8("Nova Cena"), this);
    newSceneAct->setShortcuts(QKeySequence::New);
    newSceneAct->setStatusTip(QString::fromUtf8("Criar uma nava cena sem objetos."));
    connect(newSceneAct, SIGNAL(triggered()), this, SLOT(newScene()));

    QAction *openSceneAct = new QAction(QString::fromUtf8("Abrir cena"), this);
    openSceneAct->setShortcuts(QKeySequence::Open);
    openSceneAct->setStatusTip(QString::fromUtf8("Abrir uma nava cena."));
    connect(openSceneAct, SIGNAL(triggered()), this, SLOT(openScene()));

    QAction *openObjectsAct = new QAction(QString::fromUtf8("Incluir objetos"), this);
    openObjectsAct->setStatusTip(QString::fromUtf8("Inclui apenas os objetos na cena atual."));
    connect(openObjectsAct, SIGNAL(triggered()), this, SLOT(openObjects()));

    saveSceneAct = new QAction(QString::fromUtf8("Salvar cena"), this);
    saveSceneAct->setShortcuts(QKeySequence::Save);
    saveSceneAct->setStatusTip(QString::fromUtf8("Salvar cena atual."));
    saveSceneAct->setEnabled(false);
    connect(saveSceneAct, SIGNAL(triggered()), this, SLOT(saveScene()));

    QAction *saveSceneAsAct = new QAction(QString::fromUtf8("Salvar cena como..."), this);
    saveSceneAsAct->setShortcuts(QKeySequence::SaveAs);
    saveSceneAsAct->setStatusTip(QString::fromUtf8("Salvar cena atual em novo arquivo."));
    connect(saveSceneAsAct, SIGNAL(triggered()), this, SLOT(saveSceneAs()));

    QAction *exitAct = new QAction(QString::fromUtf8("Sair"), this);
    exitAct->setShortcuts(QKeySequence::Quit);
    exitAct->setStatusTip(QString::fromUtf8("Sair da aplicação."));
    connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

    QAction *showAxisAct = new QAction(QString::fromUtf8("Eixos"), this);
    showAxisAct->setCheckable(true);
    showAxisAct->setChecked(canvas->isShowingAxis());
    showAxisAct->setStatusTip(QString::fromUtf8("Mostrar eixos."));
    connect(showAxisAct, SIGNAL(toggled(bool)), canvas, SLOT(changeShowAxis(bool)));

    QAction *showGridAct = new QAction(QString::fromUtf8("Grade"), this);
    showGridAct->setCheckable(true);
    showGridAct->setChecked(canvas->isShowingGrid());
    showGridAct->setStatusTip(QString::fromUtf8("Mostrar grade."));
    connect(showGridAct, SIGNAL(toggled(bool)), canvas, SLOT(changeShowGrid(bool)));

	QAction *viewScenePanelAct = scenePanelDock->toggleViewAction();

	QAction *viewRayTestPanelAct = rayTestDock->toggleViewAction();

	QAction *viewCameraPanelAct = cameraPanelDock->toggleViewAction();

    editObjectAct = new QAction(QString::fromUtf8("Modificar objeto"), this);
    editObjectAct->setStatusTip(QString::fromUtf8("Modifica os objetos selecionados"));
    editObjectAct->setDisabled(true);
//    connect(editObjectAct, SIGNAL(triggered()), this, SLOT(editObjectDialog()));
//    connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(editObjectDialog(QTreeWidgetItem *, int)));

    deleteObjectAct = new QAction(QString::fromUtf8("Remover objetos"), this);
    deleteObjectAct->setStatusTip(QString::fromUtf8("Remove os objetos selecionados"));
    deleteObjectAct->setDisabled(true);
    connect(deleteObjectAct, SIGNAL(triggered()), scenePanel, SLOT(deleteObjects()));

    deleteLightAct = new QAction(QString::fromUtf8("Remover luzes"), this);
    deleteLightAct->setStatusTip(QString::fromUtf8("Remove as luzes selecionados"));
    deleteLightAct->setDisabled(true);
    connect(deleteLightAct, SIGNAL(triggered()), scenePanel, SLOT(deleteLights()));

    duplicateObjectAct = new QAction(QString::fromUtf8("Duplicar objeto"), this);
    duplicateObjectAct->setStatusTip(QString::fromUtf8("Duplicar objeto selecionado"));
    duplicateObjectAct->setDisabled(true);
    connect(duplicateObjectAct, SIGNAL(triggered()), scenePanel, SLOT(duplicateObject()));


    QAction *newCuboidAct = new QAction(QIcon("bitmaps/cuboid.xpm"), QString::fromUtf8("Novo hexaedro"), this);
    newCuboidAct->setStatusTip(QString::fromUtf8("Cria um novo hexaedro, definido pelo seu ponto mínimo e máximo."));
    connect(newCuboidAct, SIGNAL(triggered()), this, SLOT(newCuboidPrimitiveDialog()));

    QAction *newSphereAct = new QAction(QIcon("bitmaps/sphere.xpm"), QString::fromUtf8("Nova esfera"), this);
    newSphereAct->setStatusTip(QString::fromUtf8("Cria uma nova esfera, definida pelo centro e raio."));
    connect(newSphereAct, SIGNAL(triggered()), this, SLOT(newSpherePrimitiveDialog()));

    QAction *newCylinderAct = new QAction(QIcon("bitmaps/cylinder.xpm"), QString::fromUtf8("Novo cilindro"), this);
    newCylinderAct->setStatusTip(QString::fromUtf8("Cria um novo cilindro, definido pelo centro, raio e altura."));
    connect(newCylinderAct, SIGNAL(triggered()), this, SLOT(newCylinderPrimitiveDialog()));

    QAction *newConeAct = new QAction(QIcon("bitmaps/cone.xpm"), QString::fromUtf8("Novo cone"), this);
    newConeAct->setStatusTip(QString::fromUtf8("Cria um novo cone, definido pelo centro, raio e altura."));
    connect(newConeAct, SIGNAL(triggered()), this, SLOT(newConePrimitiveDialog()));


    newPointlLightAct = new QAction(QIcon("bitmaps/pontual.xpm"), QString::fromUtf8("Nova luz pontual"), this);
    newPointlLightAct->setStatusTip(QString::fromUtf8("Cria uma nova luz pontual."));
    connect(newPointlLightAct, SIGNAL(triggered()), this, SLOT(newPointLightDialog()));

    newAreaLightAct = new QAction(QIcon("bitmaps/area.xpm"), QString::fromUtf8("Nova luz em area"), this);
    newAreaLightAct->setStatusTip(QString::fromUtf8("Cria uma nova luz em area."));
    connect(newAreaLightAct, SIGNAL(triggered()), this, SLOT(newAreaLightDialog()));


    QAction *unionAct = new QAction(QIcon("bitmaps/union.xpm"), QString::fromUtf8("União"), this);
    unionAct->setStatusTip(QString::fromUtf8("Cria um objeto sendo a união de todos os selecionados."));
    connect(unionAct, SIGNAL(triggered()), scenePanel, SLOT(unionOperation()));

    QAction *intersectionAct = new QAction(QIcon("bitmaps/intersection.xpm"), QString::fromUtf8("Interseção"), this);
    intersectionAct->setStatusTip(QString::fromUtf8("Cria um objeto sendo a interseção de todos os selecionados."));
    connect(intersectionAct, SIGNAL(triggered()), scenePanel, SLOT(intersectionOperation()));

    QAction *differenceAct = new QAction(QIcon("bitmaps/difference.xpm"), QString::fromUtf8("Diferença"), this);
    differenceAct->setStatusTip(QString::fromUtf8("Cria um objeto sendo a diferença de todos os selecionados."));
    connect(differenceAct, SIGNAL(triggered()), scenePanel, SLOT(differenceOperation()));

    QAction *translateAct = new QAction(QIcon("bitmaps/translate.xpm"), QString::fromUtf8("Translação"), this);
    translateAct->setStatusTip(QString::fromUtf8("Translada os objetos selecionados."));
    connect(translateAct, SIGNAL(triggered()), objectsTree, SLOT(translateOperation()));

    QAction *rotateAct = new QAction(QIcon("bitmaps/rotate.xpm"), QString::fromUtf8("Rotação"), this);
    rotateAct->setStatusTip(QString::fromUtf8("Rotaciona os objetos selecionados."));
    connect(rotateAct, SIGNAL(triggered()), objectsTree, SLOT(rotateOperation()));

    QAction *scaleAct = new QAction(QIcon("bitmaps/scale.xpm"), QString::fromUtf8("Escala"), this);
    scaleAct->setStatusTip(QString::fromUtf8("Escalona os objetos selecionados."));
    connect(scaleAct, SIGNAL(triggered()), objectsTree, SLOT(scaleOperation()));

    QAction *wireframeAct = new QAction(QIcon("bitmaps/wireframe.xpm"), QString::fromUtf8("Wireframe"), this);
    wireframeAct->setStatusTip(QString::fromUtf8("Desenha os objetos em wireframe."));
    wireframeAct->setCheckable(true);
    connect(wireframeAct, SIGNAL(toggled(bool)), canvas, SLOT(changeObjectView(bool)));

    QAction *showPhotonsAct = new QAction(QIcon("bitmaps/photons.xpm"), QString::fromUtf8("Fótons"), this);
    showPhotonsAct->setStatusTip(QString::fromUtf8("Desenha os fótons."));
    showPhotonsAct->setCheckable(true);
    connect(showPhotonsAct, SIGNAL(toggled(bool)), canvas, SLOT(changePhotonView(bool)));

    QAction *showCameraAct = new QAction(QIcon("bitmaps/camera.xpm"), QString::fromUtf8("Camera"), this);
    showCameraAct->setStatusTip(QString::fromUtf8("Desenha plano focal."));
    showCameraAct->setCheckable(true);
    connect(showCameraAct, SIGNAL(toggled(bool)), canvas, SLOT(changeShowCamera(bool)));

    rayTestViewAct = new QAction(QIcon("bitmaps/ray.xpm"), QString::fromUtf8("Raio de teste"), this);
    rayTestViewAct->setStatusTip(QString::fromUtf8("Mostra o raio que está sendo testado."));
    rayTestViewAct->setCheckable(true);
    connect(rayTestViewAct, SIGNAL(toggled(bool)), canvas, SLOT(changeShowRayTest(bool)));


    lightsTree->addAction(deleteLightAct);
    objectsTree->addAction(deleteObjectAct);
    objectsTree->addAction(duplicateObjectAct);

    //Criando toolbar ----------------------------------------------------------
    QToolBar *objectsToolBar = addToolBar(tr("Barra de primitivas"));
    objectsToolBar->addAction(newCuboidAct);
    objectsToolBar->addAction(newSphereAct);
    objectsToolBar->addAction(newCylinderAct);
    objectsToolBar->addAction(newConeAct);

    QToolBar *lightsToolBar = addToolBar(tr("Barra de luzes"));
    lightsToolBar->addAction(newPointlLightAct);
    lightsToolBar->addAction(newAreaLightAct);

    setOperationToolBar = addToolBar(QString::fromUtf8("Barra de operações de conjuntos"));
    setOperationToolBar->addAction(unionAct);
    setOperationToolBar->addAction(intersectionAct);
    setOperationToolBar->addAction(differenceAct);
    setOperationToolBar->setDisabled(true);

    geometricOperationToolBar = addToolBar(QString::fromUtf8("Barra de operações geométricas"));
    geometricOperationToolBar->addAction(translateAct);
    geometricOperationToolBar->addAction(rotateAct);
    geometricOperationToolBar->addAction(scaleAct);
    geometricOperationToolBar->setDisabled(true);



    QToolBar *wireframeToolBar = addToolBar(QString::fromUtf8("Barra de visualização"));
    wireframeToolBar->addAction(wireframeAct);
    wireframeToolBar->addAction(showPhotonsAct);
    wireframeToolBar->addAction(showCameraAct);
    wireframeToolBar->addAction(rayTestViewAct);


	QAction *veiwObjectsToolBarAct = objectsToolBar->toggleViewAction();
	QAction *veiwLightsToolBarAct = lightsToolBar->toggleViewAction();
	QAction *veiwSetOperationToolBarAct = setOperationToolBar->toggleViewAction();
	QAction *veiwGeometricOperationToolBarAct = geometricOperationToolBar->toggleViewAction();
	QAction *viewWireframeToolBarAct = wireframeToolBar->toggleViewAction();

    //Criando menus ------------------------------------------------------------
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *viewMenu;

    fileMenu = menuBar()->addMenu(QString::fromUtf8("&Arquivo"));
    fileMenu->addAction(newSceneAct);
    fileMenu->addSeparator();
    fileMenu->addAction(openObjectsAct);
    fileMenu->addAction(openSceneAct);
    fileMenu->addSeparator();
    fileMenu->addAction(saveSceneAct);
    fileMenu->addAction(saveSceneAsAct);
    fileMenu->addSeparator();
    fileMenu->addAction(exitAct);

    viewMenu = menuBar()->addMenu(QString::fromUtf8("&Visualizar"));
    viewMenu->addAction(showAxisAct);
    viewMenu->addAction(showGridAct);
    viewMenu->addSeparator();
    viewMenu->addAction(viewScenePanelAct);
    viewMenu->addAction(viewRayTestPanelAct);
    viewMenu->addAction(viewCameraPanelAct);
    viewMenu->addSeparator();
    viewMenu->addAction(veiwObjectsToolBarAct);
    viewMenu->addAction(veiwLightsToolBarAct);
    viewMenu->addAction(veiwSetOperationToolBarAct);
    viewMenu->addAction(veiwGeometricOperationToolBarAct);
    viewMenu->addAction(viewWireframeToolBarAct);


    editMenu = menuBar()->addMenu(QString::fromUtf8("&Editar"));
    editMenu->addAction(editObjectAct);
    editMenu->addAction(deleteObjectAct);
    editMenu->addAction(duplicateObjectAct);
    editMenu->addSeparator();
}

void Window::updateActionsFromChanging(){
    setOperationToolBar->setDisabled(true);
    geometricOperationToolBar->setDisabled(true);
    deleteObjectAct->setDisabled(true);
    duplicateObjectAct->setDisabled(true);
    saveSceneAct->setEnabled(true);


    if(rayTestViewAct->isChecked()){
        rayTestViewAct->setChecked(false);
        canvas->getScene()->clearTestRay();
    }

    canvas->getScene()->clearTree();
    renderPanel->enableHBBPushButton();

    updateActionsFromLight();

    canvas->updateGL();
}

void Window::updateActionsFromChanging(int _selectedSize){
    setOperationToolBar->setDisabled(_selectedSize<2);
    geometricOperationToolBar->setDisabled(_selectedSize<1);
    deleteObjectAct->setDisabled(_selectedSize!=1);
    duplicateObjectAct->setDisabled(_selectedSize!=1);
    saveSceneAct->setEnabled(true);


    if(rayTestViewAct->isChecked()){
        rayTestViewAct->setChecked(false);
        canvas->getScene()->clearTestRay();
    }

    canvas->getScene()->clearTree();
    renderPanel->enableHBBPushButton();

    updateActionsFromLight();

    canvas->updateGL();
}

void Window::updateActionsFromEditing(int _previousSize){
    setOperationToolBar->setDisabled(_previousSize<2);
    geometricOperationToolBar->setDisabled(_previousSize<1);
    deleteObjectAct->setDisabled(true);
    duplicateObjectAct->setDisabled(true);
    saveSceneAct->setEnabled(true);

    canvas->updateGL();
}

void Window::updateActionsFromSelection(int _selectedSize){
    setOperationToolBar->setEnabled(_selectedSize > 1);
    geometricOperationToolBar->setEnabled(_selectedSize > 0);
    editObjectAct->setEnabled(_selectedSize > 0);
    deleteObjectAct->setEnabled(_selectedSize == 1);
    duplicateObjectAct->setEnabled(_selectedSize == 1);

    canvas->updateGL();
}

void Window::updateActionsFromLight(int _totalSize, int _selectedSize){

    canvas->getScene()->clearPhotonsMaps();
    if(_totalSize == -1 && _selectedSize == -1){
        canvas->updateGL();
        return;
    }


    bool b = _totalSize > 8;
    newAreaLightAct->setDisabled(b);
    newPointlLightAct->setDisabled(b);
    deleteLightAct->setEnabled(_selectedSize == 1);

    canvas->updateGL();
}

#endif //!USE_CONSOLE
